/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */

package com.ykht.proj.activity.controller.c;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ykht.proj.activity.entity.VInfo;
import com.ykht.proj.activity.service.VInfoService;
import com.ykht.proj.activity.vo.*;
import com.ykht.proj.common.core.util.R;
import com.ykht.proj.common.log.annotation.SysLog;
import com.ykht.proj.common.security.util.SecurityUtils;
import com.ykht.proj.coupon.vo.BaseLonLat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 持卡人表（会员卡）
 *
 * @author csg
 * @date 2021-05-21 14:22:59
 */
@RestController
@AllArgsConstructor
@RequestMapping("c/vinfo" )
@Api(value = "vinfo", tags = "c端vip相关")
public class CVInfoController {

    private final  VInfoService vInfoService;

    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getVInfoPage(Page page, VInfo vInfo) {
        return R.ok(vInfoService.page(page, Wrappers.query(vInfo)));
    }
    @ApiOperation(value = "会员卡列表")
    @GetMapping("/getListBySelf" )
    public R<VInfoBySelfVo> getListBySelf(BaseLonLat lonLat,Integer status) {
		try {
			return vInfoService.getListBySelf(lonLat,status);
		} catch (Exception e) {
			e.printStackTrace();
			return R.failed("获取列表失败");
		}
	}


    @ApiOperation(value = "通过id查询会员卡详情--HC11-1“嗨”吃卡/活动卡详情")
    @GetMapping("/{id}" )
    public R<VInfoCard> getById(@PathVariable("id" ) Long id) {
		try {
			return R.ok(vInfoService.getInfoById(id));
		} catch (Exception e) {
			e.printStackTrace();
			return  R.failed("查询失败");
		}
	}
    @ApiOperation(value = "兑换卡")
    @GetMapping("exchange/{code}" )
    public R exchange(@PathVariable("code" ) String code) {
		try {
			return vInfoService.exchange(code);
		} catch (Exception e) {
			e.printStackTrace();
			return R.failed("兑换失败");
		}
	}
    @ApiOperation(value = "通过会员卡id查询可用门店")
    @GetMapping("cardShopList/{vId}" )
    public R<List<VCardInfo.ShopVo>> cardShopList(@PathVariable("vId" ) Long vId, BaseLonLat lonLat) {
		try {
			return vInfoService.cardShopList(vId,lonLat);
		} catch (Exception e) {
			e.printStackTrace();
			return R.failed("查询失败");
		}
	}

	@GetMapping(value = "myCount/{loginId}")
	public R<Integer> myVinfoCount(@PathVariable("loginId") Long loginId){
		Integer unExpireNum = vInfoService.count(Wrappers.lambdaQuery(VInfo.class).eq(VInfo::getPersonId, loginId).eq(VInfo::getStatus,0));
    	return R.ok(unExpireNum);
	}

}
